<?php
if (isset($_REQUEST['link'])) {
	
	$data = unserialize(file_get_contents('msgs.txt'));
	$chunk = preg_split("/(\r\n\r\n)/", $data);

	$num_chunks = count($chunk);
	$num_chunks = $num_chunks*10;

	$time = time() - $_COOKIE["nend_sig"];

	while ($time > $num_chunks) {
		$time = $time - $num_chunks;
	}
	if ($time >= 10) {
     	$time = substr($time, 0, -1);
	} else {
		$time = 0;
	}

	$msg = $chunk[$time];

	preg_match("#((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie", $chunk[$time], $url);
	header( 'Location: '.$url[0] ) ;
} else {
	setcookie('nend_sig', time(), time()+1800);
	header('Content-Type: image/png');
	readfile('./signature.png');
}
?>